package com.spring.aop;

import com.spring.utils.ConnectionUtils;

import java.sql.SQLException;

/**
 * @author SpringWang
 * @date 2021/5/20
 */
public class TransactionManager {

    private TransactionManager() {
    }

    private static final TransactionManager MANAGER = new TransactionManager();

    public static TransactionManager getInstance() {
        return MANAGER;
    }

    public void begin() throws SQLException {
        ConnectionUtils.getInstance().getCurrentThreadConn().setAutoCommit(false);
    }

    public void commit() throws SQLException {
        ConnectionUtils.getInstance().getCurrentThreadConn().commit();
    }

    public void rollback() throws SQLException {
        ConnectionUtils.getInstance().getCurrentThreadConn().rollback();
    }
}
